﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ESMAM.BLL.SYS;
using ESMAM.Model;
using ESMAM.Tools;
using ESMAM.Web.Core;

namespace ESMAM.WebApp.Controllers
{
    public class LangController : BaseController
    {
        // GET: Lang
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult LangSearch(int pageCurrent, int pageSize, string orders)
        {
            var ret = LangBLL.GetPager(Request.Form);
            if (ret.Code == -1)
            {
                return this.JsonBJUI(300, ret.Msg);
            }
            Pager pager = ret.Value;
            return this.JsonNet(pager);
        }


        [HttpPost]
        public ActionResult LangUpsert()
        {
            var ret = LangBLL.Upsert(Request.Form);
            if (ret.Code == -1)
            {
                return this.JsonBJUI(300, ret.Msg);
            }
            return this.JsonBJUI(200, ret.Msg);
        }

        [HttpPost]
        public ActionResult DelLang(string id)
        {
            var ret = LangBLL.Delete(id);
            if (ret.Code == -1)
            {
                return this.JsonBJUI(300, ret.Msg);
            }
            return this.JsonBJUI(200, "删除成功！");
        }

        [HttpGet]
        public ActionResult SetLang(Lang lg)
        {
            var ret = LangBLL.SetLang(CurrUser.id.ToString(), lg);
            if (ret.Code == 1)
            {
                CurrUser.shiyyy = lg;
                CookieHelper.SetCookie(BaseController.CONST_COOKIE_LANG, lg.ToString(), DateTime.Now.AddDays(15));
            }
            return this.JsonNet(LangBLL.SetLang(CurrUser.id.ToString(), lg));
        }

        [HttpPost]
        public ActionResult FanYin(string type,bool isReplace)
        {
            Retful ret = LangBLL.FanYin(type, isReplace);
            return this.JsonNet(ret);
        }
    }
}